package com.cn.yang.servlet;

import com.alibaba.fastjson.JSONObject;
import com.cn.yang.model.mainPage.HeadLinkModel;
import com.cn.yang.model.mainPage.MainPageModel;
import com.cn.yang.model.news.NewsModel;
import com.cn.yang.model.production.ProductClassifyModel;
import com.cn.yang.service.MainPageService;
import com.cn.yang.service.NewsService;
import com.cn.yang.service.ProductService;
import com.cn.yang.service.impl.MainPageServiceImpl;
import com.cn.yang.service.impl.NewsServiceImpl;
import com.cn.yang.service.impl.ProductServiceImpl;
import com.cn.yang.util.PageUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/main")
public class MainServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //====================================================================================
        //主页面的内容： 模块名称
        MainPageService service = new MainPageServiceImpl();
        List<MainPageModel> mainPagelist = service.findMainPage();
        
        
// 第一部分的<!-- 某某医疗设备设施-->的六张标题
        ProductService servlet = new ProductServiceImpl();
        List<ProductClassifyModel> productClassifylist = servlet.findClassify();
        // //新闻时间内容--取部分
        NewsService newsService = new NewsServiceImpl();
        NewsModel model = new NewsModel();
        PageUtil pageUtil = new PageUtil();
        pageUtil.setPageNumber(1);
        pageUtil.setPageSize(8);
        model.setPageUtil(pageUtil);
        List<NewsModel> newslist= newsService.findNews(model);
        //主页面的跳转链接
        MainPageService headLink = new MainPageServiceImpl();
        List<HeadLinkModel> list = headLink.selectHeadLink();
        
    
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("mainPagelist",mainPagelist);
        jsonObject.put("productClassifylist",productClassifylist);
        jsonObject.put("newslist",newslist);
        jsonObject.put("list",list);
        resp.getWriter().println(jsonObject);
    }
}
